---
category: String
created: '2020-06-15'
title: Replace the first given number of characters of a string with another character
updated: '2021-10-13'
---

**JavaScript version**

```js mask.js
const mask = (str, num, mask) => `${str}`.slice(num).padStart(`${str}`.length, mask);
```

**TypeScript version**

```ts mask.ts
const mask = (str: string, num: number, mask: string): string => `${str}`.slice(num).padStart(`${str}`.length, mask);
```

**Examples**

```js examples.js
mask(1234567890, 3, '*'); // ***4567890
```
